package com.sfj.common.util;

/**
 * @author kaka
 * @Date 2025/04/28
 */
public class CamelCaseUtil {

    //下划线转驼峰
    public static String underlineToCamelSafe(String name) {
        if (name == null || name.isEmpty()) {
            return name;
        }
        if (!name.contains("_")) {
            // 本来就没有下划线，不处理
            return name;
        }
        StringBuilder result = new StringBuilder();
        boolean upperCase = false;
        for (int i = 0; i < name.length(); i++) {
            char c = name.charAt(i);
            if (c == '_') {
                upperCase = true;
            } else {
                if (upperCase) {
                    result.append(Character.toUpperCase(c));
                    upperCase = false;
                } else {
                    result.append(c);
                }
            }
        }
        return result.toString();
    }
}
